using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using UniversalAdmin.Application.Commands;
using UniversalAdmin.Application.Dto;
using UniversalAdmin.Application.Services;
using UniversalAdmin.Api.Filters;

[ApiController]
[Route("api/roles/{roleId}/permissions")]
[Authorize]
public class RolePermissionMappingsController : ControllerBase
{
    private readonly IAppRolePermissionServices _service;
    public RolePermissionMappingsController(IAppRolePermissionServices service) { _service = service; }

    // [HttpPost] 方法已删除，避免路由冲突

    [HttpGet]
    [RequirePermission("role.view")] // 需要查看角色权限
    public async Task<ApiResult<IEnumerable<object>>> GetRolePermissions(Guid roleId)
    {
        return await _service.GetRolePermissionsAsync(roleId);
    }

    /// <summary>
    /// 获取角色的详细权限信息
    /// </summary>
    /// <param name="roleId">角色ID</param>
    /// <returns>权限详细信息列表</returns>
    [HttpGet("detail")]
    [RequirePermission("role.view")] // 需要查看角色权限
    public async Task<ApiResult<IEnumerable<PermissionDto>>> GetRolePermissionsDetail(Guid roleId)
    {
        return await _service.GetRolePermissionsDetailAsync(roleId);
    }

    [HttpDelete("{permissionId}")]
    [RequirePermission("role.manage")] // 需要管理角色权限
    public async Task<ApiResult> RemoveRolePermission(Guid roleId, Guid permissionId)
    {
        return await _service.RemoveRolePermissionAsync(roleId, permissionId);
    }
} 